<template>
  <j-modal
    :title="title"
    :width="width"
    :visible="visible"
    switchFullscreen
    @ok="handleOk"
    :confirmLoading="confirmLoading"
    :okButtonProps="{ class:{'jee-hidden': disableSubmit} }"
    @cancel="handleCancel"
    cancelText="关闭">
    <sk-questionnaire-send-form ref="realForm" @modelLoading="getConfirmLoading" @ok="submitCallback" :disabled="disableSubmit"></sk-questionnaire-send-form>
  </j-modal>
</template>

<script>
  import { httpAction, getAction } from '@/api/manage'
  import SkQuestionnaireSendForm from './SkQuestionnaireSendForm'
  export default {
    name: 'SkQuestionnaireSendModal',
    components: {
      SkQuestionnaireSendForm
    },
    data () {
      return {
        title:'',
        width:800,
        visible: false,
        disableSubmit: false,
        confirmLoading: false
      }
    },
    methods: {
      getConfirmLoading(data){
        this.confirmLoading = data;
      },
      // 查询问卷设置详情
      init(record){
        this.visible = true;
        const url = "/family/skQuestionnaire/queryById"
        const params = {
          id:record.baseId
        }
        getAction(url,params).then((res)=>{
          if(res.success){
            this.edit(res.result)
          } else {
            this.$message.warning(res.message);
          }
        }).catch((error)=>{
          console.error(error);
        })
        
      },
      add () {
        this.visible=true
        this.$nextTick(()=>{
          this.$refs.realForm.add();
        })
      },
      edit (record) {
        this.visible=true
        this.$nextTick(()=>{
          this.$refs.realForm.edit(record);
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        this.$refs.realForm.submitForm();
      },
      submitCallback(){
        this.$emit('ok');
        this.visible = false;
      },
      handleCancel () {
        this.close()
      }
    }
  }
</script>